import React, { Component } from 'react'
import {
    Button,
    InputItem,
    List,
    NavBar,
    WhiteSpace,
    TextareaItem
} from "antd-mobile";
import HeaderSelector from '../../compoments/header_selector/headerSelector'
import { connect } from 'react-redux'
import { createForm } from 'rc-form'
import { update } from '../../redux/action'
import { Redirect } from 'react-router-dom'

class BossInfo extends Component{

    state = {
        header:'',
        port:'',
        company:'',
        salary: '',
        info:''
    }
    getHeader = (header) =>{
        this.setState({
            header
        })
    }


    saveInfo =()=>{
        this.props.form.validateFields((error,value)=>{
            this.setState(value,()=>{
                this.props.update(this.state)
            })
        })
    }
    render() {
        let errors
        const { getFieldProps,getFieldError } = this.props.form;

        const { userType, header } = this.props.user
        if (header) {
            const path = userType === 'boss' ? '/boss' : '/jobSeeker'
            return <Redirect to={path} />
        }
        return(
            <div>
                <HeaderSelector getHeader={this.getHeader} />
                <WhiteSpace/>
                <List>
                    <WhiteSpace/>
                    <InputItem
                        {...getFieldProps('port')}
                        placeholder='请输入招聘岗位'
                    >招聘岗位：</InputItem>
                    <WhiteSpace/>
                    <InputItem
                        {...getFieldProps('company')}
                        placeholder='请输入公司名称'
                    >公司名称：</InputItem>
                    <WhiteSpace/>
                    <InputItem
                        {...getFieldProps('salary')}
                        placeholder='请输入职位薪资'
                    >职位薪资：</InputItem>
                    <WhiteSpace/>
                    <TextareaItem
                        title='职位要求：'
                        autoHeight
                        {...getFieldProps('info')}
                    />
                    <WhiteSpace/>

                    <Button type='primary'  onClick={this.saveInfo}>保存</Button>
                </List>
            </div>
        )
    }
}

export default connect(
    state=>({ user:state.user }),
    {update}
)(createForm()(BossInfo))